home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / CodeWarrior Lite / Metrowerks C⁄C++ Lite / Headers / ANSI Headers / math.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-03-28  |  10.6 KB  |  404 lines  |  [TEXT/MMCC]

  1. /* math.h standard header */
  2. #ifdef __MWERKS__
  3.  
  4. #ifndef __MATH__
  5. #define    __MATH__
  6.  
  7. #pragma options align=mac68k
  8.  
  9.         /* common macros */
  10. #define _PI            pi
  11. #define HUGE_VAL    __inf()
  12.  
  13.         /*
  14.          *    Set the following define to 1 to force the ANSI math header to inline FPU calls
  15.          *    whenever possible.  This behaviour is not ANSI compatible, so should be used with
  16.          *    care.
  17.          *    NB: on 680x0 macs, using inlines in conjunction with 8byte doubles will not work
  18.          *    correctly.
  19.          */
  20. #if !defined(_INLINE_FPU_CALLS_)
  21. #define _INLINE_FPU_CALLS_ 0
  22. #endif
  23.  
  24.         /* common type definitions */
  25. typedef union {
  26.     unsigned short _W[5];
  27.     float _F;
  28.     double _D;
  29.     long double _L;
  30.     } _Dconst;
  31.  
  32. #ifndef _YVALS
  33. #include <yvals.h>
  34. #endif
  35.  
  36.         /* function prototype declarations (common to both 68K and PPC) */
  37. _C_LIB_DECL
  38.         /* float declarations */
  39. float cosf(float);
  40. float sinf(float);
  41. float tanf(float);
  42. float acosf(float);
  43. float asinf(float);
  44. float atanf(float);
  45. float atan2f(float, float);
  46. float coshf(float);
  47. float sinhf(float);
  48. float tanhf(float);
  49. float expf(float);
  50. float frexpf(float, int *);
  51. float ldexpf(float, int);
  52. float logf(float);
  53. float log10f(float);
  54. float modff(float, float*);
  55. float fabsf(float);
  56. float powf(float, float);
  57. float sqrtf(float);
  58. float ceilf(float);
  59. float floorf(float);
  60. float fmodf(float, float);
  61.         /* double declarations */
  62. double cos(double);
  63. double sin(double);
  64. double tan(double);
  65. double acos(double);
  66. double asin(double);
  67. double atan(double);
  68. double atan2(double, double);
  69. double cosh(double);
  70. double sinh(double);
  71. double tanh(double);
  72. double exp(double);
  73. double frexp(double, int *);
  74. double ldexp(double, int);
  75. double log(double);
  76. double log10(double);
  77. double modf(double, double *);
  78. double fabs(double);
  79. double pow(double, double);
  80. double sqrt(double);
  81. double ceil(double);
  82. double floor(double);
  83. double fmod(double, double);
  84. _END_C_LIB_DECL
  85.  
  86. #if powerc
  87.  
  88.         /* constants */
  89. extern const double pi;
  90.         /* function prototypes */
  91. _C_LIB_DECL
  92.         /* infinity function */
  93. double __inf ( void );
  94.  
  95.         /* inline fabs call */
  96. #if _INLINE_FPU_CALLS_
  97. #define fabs(x)            __fabs(x)
  98. #endif
  99. _END_C_LIB_DECL
  100.  
  101. #else    /* !powerc */
  102.  
  103.         /* constants */
  104. extern const long double pi;
  105.         /* function prototypes */
  106. _C_LIB_DECL
  107.         /* infinity function */
  108. long double __inf ( void );
  109.  
  110.         /* double macro overrides */
  111. #if _INLINE_FPU_CALLS_ && __MC68881__
  112.         /* call the FPU directly (NOT ANSI COMPATIBLE) */
  113. long double _fpucos(long double:__FP0):__FP0 = { 0xF200,0x001D };
  114. long double _fpusin(long double:__FP0):__FP0 = { 0xF200,0x000E };
  115. long double _fputan(long double:__FP0):__FP0 = { 0xF200,0x000F };
  116. long double _fpuacos(long double:__FP0):__FP0 = { 0xF200,0x001C };
  117. long double _fpuasin(long double:__FP0):__FP0 = { 0xF200,0x000C };
  118. long double _fpuatan(long double:__FP0):__FP0 = { 0xF200,0x000A };
  119. long double _fpucosh(long double:__FP0):__FP0 = { 0xF200,0x0019 };
  120. long double _fpusinh(long double:__FP0):__FP0 = { 0xF200,0x0002 };
  121. long double _fputanh(long double:__FP0):__FP0 = { 0xF200,0x0009 };
  122. long double _fpuexp(long double:__FP0):__FP0 = { 0xF200,0x0010 };
  123. long double _fpuldexp(long double:__FP0,long:__D0):__FP0 = { 0xF200,0x4026 };
  124. long double _fpulog(long double:__FP0):__FP0 = { 0xF200,0x0014 };
  125. long double _fpulog10(long double:__FP0):__FP0 = { 0xF200,0x0015 };
  126. long double _fpufabs(long double:__FP0):__FP0 = { 0xF200,0x0018 };
  127. long double _fpusqrt(long double:__FP0):__FP0 = { 0xF200,0x0004 };
  128. long double _fpufmod(long double:__FP0,long double:__FP1):__FP0 = { 0xF200,0x0421 };
  129. #define cos(x)            _fpucos(x)
  130. #define sin(x)            _fpusin(x)
  131. #define tan(x)            _fputan(x)
  132. #define acos(x)            _fpuacos(x)
  133. #define asin(x)            _fpuasin(x)
  134. #define atan(x)            _fpuatan(x)
  135. #define cosh(x)            _fpucosh(x)
  136. #define sinh(x)            _fpusinh(x)
  137. #define tanh(x)            _fputanh(x)
  138. #define exp(x)            _fpuexp(x)
  139. #define ldexp(x,n)        _fpuldexp(x,n)
  140. #define log(x)            _fpulog(x)
  141. #define log10(x)        _fpulog10(x)
  142. #define fabs(x)            _fpufabs(x)
  143. #define sqrt(x)            _fpusqrt(x)
  144. #define fmod(x,y)        _fpufmod(x,y)
  145. #else
  146.         /* ANSI compatible double overrides */
  147. double cosd(double);
  148. double sind(double);
  149. double tand(double);
  150. double acosd(double);
  151. double asind(double);
  152. double atand(double);
  153. double coshd(double);
  154. double sinhd(double);
  155. double tanhd(double);
  156. double expd(double);
  157. double ldexpd(double, int);
  158. double logd(double);
  159. double log10d(double);
  160. double fabsd(double);
  161. double sqrtd(double);
  162. double fmodd(double, double);
  163. #define cos(x)            cosd(x)
  164. #define sin(x)            sind(x)
  165. #define tan(x)            tand(x)
  166. #define acos(x)            acosd(x)
  167. #define asin(x)            asind(x)
  168. #define atan(x)            atand(x)
  169. #define cosh(x)            coshd(x)
  170. #define sinh(x)            sinhd(x)
  171. #define tanh(x)            tanhd(x)
  172. #define exp(x)            expd(x)
  173. #define ldexp(x,n)        ldexpd(x,n)
  174. #define log(x)            logd(x)
  175. #define log10(x)        log10d(x)
  176. #define fabs(x)            fabsd(x)
  177. #define sqrt(x)            sqrtd(x)
  178. #define fmod(x,y)        fmodd(x,y)
  179. #endif
  180.         /* following cannot be inlined */
  181. double atan2d(double, double);
  182. double frexpd(double, int *);
  183. double modfd(double, double *);
  184. double powd(double, double);
  185. double ceild(double);
  186. double floord(double);
  187. #define atan2(x,y)        atan2d(x,y)
  188. #define frexp(x,exp)    frexpd(x,exp)
  189. #define modf(x,iptr)    modfd(x,iptr)
  190. #define pow(x,y)        powd(x,y)
  191. #define ceil(x)            ceild(x)
  192. #define floor(x)        floord(x)
  193.         /* long double declarations */
  194. long double cosl(long double);
  195. long double sinl(long double);
  196. long double tanl(long double);
  197. long double acosl(long double);
  198. long double asinl(long double);
  199. long double atanl(long double);
  200. long double atan2l(long double, long double);
  201. long double coshl(long double);
  202. long double sinhl(long double);
  203. long double tanhl(long double);
  204. long double expl(long double);
  205. long double frexpl(long double, int *);
  206. long double ldexpl(long double, int);
  207. long double logl(long double);
  208. long double log10l(long double);
  209. long double modfl(long double, long double *);
  210. long double fabsl(long double);
  211. long double powl(long double, long double);
  212. long double sqrtl(long double);
  213. long double ceill(long double);
  214. long double floorl(long double);
  215. long double fmodl(long double, long double);
  216.         /* internally used functions */
  217. double _Sinh(double, double);
  218. double _Cosh(double, double);
  219. long double _LCosh(long double, long double);
  220. long double _LSinh(long double, long double);
  221. _END_C_LIB_DECL
  222.  
  223. #endif    /* powerc */
  224.  
  225. #pragma options align=reset
  226.  
  227. #endif    /* __MATH__ */
  228.  
  229. #else    /* !__MWERKS__ */
  230.  
  231. #ifndef _MATH
  232. #define _MATH
  233. #include <yvals.h>
  234.         /* macros */
  235. #define HUGE_VAL    _Hugeval._D
  236.         /* type definitions */
  237. #if defined(__CENTERLINE__)
  238. typedef struct {
  239. #else
  240. typedef union {
  241. #endif
  242.     unsigned short _W[5];
  243.     float _F;
  244.     double _D;
  245.     long double _L;
  246.     } _Dconst;
  247. _C_LIB_DECL
  248.         /* double declarations */
  249. double acos(double);
  250. double asin(double);
  251. double atan(double);
  252. double atan2(double, double);
  253. double ceil(double);
  254. double exp(double);
  255. double fabs(double);
  256. double floor(double);
  257. double fmod(double, double);
  258. double frexp(double, int *);
  259. double ldexp(double, int);
  260. double modf(double, double *);
  261. double pow(double, double);
  262. double sqrt(double);
  263. double tan(double);
  264. double tanh(double);
  265. double _Cosh(double, double);
  266. double _Log(double, int);
  267. double _Sin(double, unsigned int);
  268. double _Sinh(double, double);
  269. extern const _Dconst _Hugeval;
  270.         /* float declarations */
  271. float acosf(float);
  272. float asinf(float);
  273. float atanf(float);
  274. float atan2f(float, float);
  275. float ceilf(float);
  276. float expf(float);
  277. float fabsf(float);
  278. float floorf(float);
  279. float fmodf(float, float);
  280. float frexpf(float, int *);
  281. float ldexpf(float, int);
  282. float modff(float, float *);
  283. float powf(float, float);
  284. float sqrtf(float);
  285. float tanf(float);
  286. float tanhf(float);
  287. float _FCosh(float, float);
  288. float _FLog(float, int);
  289. float _FSin(float, unsigned int);
  290. float _FSinh(float, float);
  291.         /* long double declarations */
  292. long double acosl(long double);
  293. long double asinl(long double);
  294. long double atanl(long double);
  295. long double atan2l(long double, long double);
  296. long double ceill(long double);
  297. long double expl(long double);
  298. long double fabsl(long double);
  299. long double floorl(long double);
  300. long double fmodl(long double, long double);
  301. long double frexpl(long double, int *);
  302. long double ldexpl(long double, int);
  303. long double modfl(long double, long double *);
  304. long double powl(long double, long double);
  305. long double sqrtl(long double);
  306. long double tanl(long double);
  307. long double tanhl(long double);
  308. long double _LCosh(long double, long double);
  309. long double _LLog(long double, int);
  310. long double _LSin(long double, unsigned int);
  311. long double _LSinh(long double, long double);
  312. _END_C_LIB_DECL
  313. #ifdef __cplusplus
  314.         /* double inlines, for C++ */
  315. inline double cos(double _X)
  316.     {return (_Sin(_X, 1)); }
  317. inline double cosh(double _X)
  318.     {return (_Cosh(_X, 1)); }
  319. inline double log(double _X)
  320.     {return (_Log(_X, 0)); }
  321. inline double log10(double _X)
  322.     {return (_Log(_X, 1)); }
  323. inline double sin(double _X)
  324.     {return (_Sin(_X, 0)); }
  325. inline double sinh(double _X)
  326.     {return (_Sinh(_X, 1)); }
  327.         /* float inlines, for C++ */
  328. inline float cosf(float _X)
  329.     {return (_FSin(_X, 1)); }
  330. inline float coshf(float _X)
  331.     {return (_FCosh(_X, 1)); }
  332. inline float logf(float _X)
  333.     {return (_FLog(_X, 0)); }
  334. inline float log10f(float _X)
  335.     {return (_FLog(_X, 1)); }
  336. inline float sinf(float _X)
  337.     {return (_FSin(_X, 0)); }
  338. inline float sinhf(float _X)
  339.     {return (_FSinh(_X, 1)); }
  340.         /* long double inlines, for C++ */
  341. inline long double cosl(long double _X)
  342.     {return (_LSin(_X, 1)); }
  343. inline long double coshl(long double _X)
  344.     {return (_LCosh(_X, 1)); }
  345. inline long double logl(long double _X)
  346.     {return (_LLog(_X, 0)); }
  347. inline long double log10l(long double _X)
  348.     {return (_LLog(_X, 1)); }
  349. inline long double sinl(long double _X)
  350.     {return (_LSin(_X, 0)); }
  351. inline long double sinhl(long double _X)
  352.     {return (_LSinh(_X, 1)); }
  353. #else
  354.         /* double macro overrides, for C */
  355. double cos(double);
  356. double cosh(double);
  357. double log(double);
  358. double log10(double);
  359. double sin(double);
  360. double sinh(double);
  361. #define cos(x)        _Sin(x, 1)
  362. #define cosh(x)        _Cosh(x, 1)
  363. #define log(x)        _Log(x, 0)
  364. #define log10(x)    _Log(x, 1)
  365. #define sin(x)        _Sin(x, 0)
  366. #define sinh(x)        _Sinh(x, 1)
  367.         /* float macro overrides, for C */
  368. float cosf(float);
  369. float coshf(float);
  370. float logf(float);
  371. float log10f(float);
  372. float sinf(float);
  373. float sinhf(float);
  374. #define cosf(x)        _FSin(x, 1)
  375. #define coshf(x)    _FCosh(x, 1)
  376. #define logf(x)        _FLog(x, 0)
  377. #define log10f(x)    _FLog(x, 1)
  378. #define sinf(x)        _FSin(x, 0)
  379. #define sinhf(x)    _FSinh(x, 1)
  380.         /* long double macro overrides, for C */
  381. long double cosl(long double);
  382. long double coshl(long double);
  383. long double logl(long double);
  384. long double log10l(long double);
  385. long double sinl(long double);
  386. long double sinhl(long double);
  387. #define cosl(x)        _LSin(x, 1)
  388. #define coshl(x)    _LCosh(x, 1)
  389. #define logl(x)        _LLog(x, 0)
  390. #define log10l(x)    _LLog(x, 1)
  391. #define sinl(x)        _LSin(x, 0)
  392. #define sinhl(x)    _LSinh(x, 1)
  393. #endif
  394.  
  395. #endif
  396.  
  397. #endif    /* __MWERKS__ */
  398.  
  399. /*
  400.  * Copyright (c) 1994 by P.J. Plauger.  ALL RIGHTS RESERVED. 
  401.  * Consult your license regarding permissions and restrictions.
  402.  */
  403.  
  404.